package masterjava.common.server.gwt.rpc.controller;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * User: Semen Abykov
 * Date: 23/05/11
 * Time: 15:47
 */
public class DownloadAttachmentController extends AbstractController {
//    @Autowired
//    private AttachmentDAO attachmentManagement;

    @Override
    protected ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
//        String id = request.getParameter("attachmentId");
//        String attachmentSourceType = request.getParameter("attachmentSourceType");
//        if (attachmentSourceType.equals(AttachmentSourceType.CONTACT_PHOTO.toString())) {
//            OutputStream out = response.getOutputStream();
//
//            attachmentManagement.downloadAttachment(Long.parseLong(id),
//                    new AbstractAttachmentStreamHandler(out) {
//
//                        @Override
//                        public void handleStreamName(String streamName) {
//                            response.setContentType(FileHelper.getContentType(streamName));
//                            response.setHeader(
//                                    "Content-Disposition",
//                                    "attachment; filename=" + streamName.replaceAll(" ", "_") + ";");
//                        }
//                    });
//            out.flush();
//            out.close();
//
//        }
        return null;
    }
}
